// pages/public/master/index.js
var network = require("../../../utils/network.js");
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    right: "http://housecleanimags-1255598775.cosbj.myqcloud.com/icon/right.png",   
  },
  toEstimate:function(){
    wx.navigateTo({
      url: '../estimate/index',
    })
  },
  toappointment:function(e){
    var index = e.currentTarget.dataset.chooseid
    var masters = this.data.master
    var master= masters[index]
    wx.setStorage({
      key:"master",
      data: master,
      success:function(){
        wx.navigateBack({
          url: '../../homeClean/hc-appointment/index',
        })
      }
    })
  },
    /**
     *    * 生命周期函数--监听页面加载
     */
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this 
    var data = {}
    data.openid = wx.getStorageSync("openid")
    data.uid = wx.getStorageSync("uid")
    data.token = wx.getStorageSync("token")
    data.offset = "0"
    data.limit = "10"
    network.getData(
      "https://api.hsb1234.com/userc/v1/cleaners",
      data,
      function(res){
        var master =res.data.data
        var star = "★"        
        for (var i = 0; i<master.length;i++){
          var starword = []
          for (var j = 0; j < master[i].star; j++){
            starword.push(star)
          }
          master[i].starword = starword.join(" ")
        }
        console.log(master)
        that.setData({
          master: master
        })
      },
      function(){}
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})